#!/usr/bin/bash

if [ -n "$IN_NIX_SHELL" ]; then
  : # Noop. In a Nix shell, fine.
elif [ -z "$(which nix)" ]; then
  echo
  echo "First install Nix — see docs/starting-talkyard.md.  Bye for now."
  echo
  exit 1
else
  echo
  echo "First start Nix shell:"
  echo
  echo "    nix develop"
  echo
  echo "Then try this script again (inside the Nix shell).  Bye."
  echo
  exit 1
fi

if [ -z "$(which deno)" ]; then
  echo
  echo "Wrong Nix shell?  I don't see any 'deno' executable, but I need"
  echo "Deno to run s/tyd.ts, which is written in Typescript.  Error.  Bye."
  echo
  exit 1
fi

if [ -z "$(which yarn)" ]; then
  echo
  echo "Wrong Nix-shell? I don't see any 'yarn' executable, but I need"
  echo "Yarn sometimes, to transpile Typescript.  Error.  Bye."
  echo
  exit 1
fi

# Download any missing Git submodules.
make git-subm-init-upd

# Download ts-node — s/tyd.js (below) calls tyd.ts (Typescript).
# Update, y2025: But isn't this directory vendored now? Gets downloaded by Git, when
# updating submodules (above)?
make node_modules

s/tyd.js "$@"
